package action.grade;

import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import model.GradeRecord;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import service.GradeService;

import com.opensymphony.xwork2.ActionSupport;

@Namespace("")
@Action(
	value="addGrade",
	results={
			@Result(name="success",type="redirect",location="addgraders?message=${message}")
	}		
)
public class addGrade extends ActionSupport{
	private int work_id;
	private String stu_id;
	private int grade;
	private String message;
	public String execute() throws Exception{ 
		GradeRecord graderecord=new GradeRecord();
		HttpServletRequest request=ServletActionContext.getRequest();
		ServletContext application=request.getServletContext();
		String schoolyear=(String) application.getAttribute("schoolyear");
		
		graderecord.setWork_id(getWork_id());
		graderecord.setStu_id(getStu_id());
		graderecord.setGrade(getGrade());
		graderecord.setSchoolyear(schoolyear);
		
		GradeService gradeservice=new GradeService();
		gradeservice.addGrade(graderecord);
		this.setMessage("addsuccess");
		return SUCCESS;
	}
	public int getWork_id() {
		return work_id;
	}
	public void setWork_id(int work_id) {
		this.work_id = work_id;
	}
	public String getStu_id() {
		return stu_id;
	}
	public void setStu_id(String stu_id) {
		this.stu_id = stu_id;
	}
	public int getGrade() {
		return grade;
	}
	public void setGrade(int grade) {
		this.grade = grade;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}

}
